package cn.iocoder.yudao.module.product.service.cylinderinoutdetail;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.product.controller.admin.cylinderinoutdetail.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.cylinderinoutdetail.CylinderInOutDetailDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.product.dal.mysql.cylinderinoutdetail.CylinderInOutDetailMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;

/**
 * 钢瓶出入库详情 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CylinderInOutDetailServiceImpl implements CylinderInOutDetailService {

    @Resource
    private CylinderInOutDetailMapper cylinderInOutDetailMapper;

    @Override
    public Long createCylinderInOutDetail(CylinderInOutDetailSaveReqVO createReqVO) {
        // 插入
        CylinderInOutDetailDO cylinderInOutDetail = BeanUtils.toBean(createReqVO, CylinderInOutDetailDO.class);
        cylinderInOutDetailMapper.insert(cylinderInOutDetail);
        // 返回
        return cylinderInOutDetail.getId();
    }

    @Override
    public void updateCylinderInOutDetail(CylinderInOutDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateCylinderInOutDetailExists(updateReqVO.getId());
        // 更新
        CylinderInOutDetailDO updateObj = BeanUtils.toBean(updateReqVO, CylinderInOutDetailDO.class);
        cylinderInOutDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteCylinderInOutDetail(Long id) {
        // 校验存在
        validateCylinderInOutDetailExists(id);
        // 删除
        cylinderInOutDetailMapper.deleteById(id);
    }

    private void validateCylinderInOutDetailExists(Long id) {
        if (cylinderInOutDetailMapper.selectById(id) == null) {
            throw exception(CYLINDER_IN_OUT_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public CylinderInOutDetailDO getCylinderInOutDetail(Long id) {
        return cylinderInOutDetailMapper.selectById(id);
    }

    @Override
    public PageResult<CylinderInOutDetailDO> getCylinderInOutDetailPage(CylinderInOutDetailPageReqVO pageReqVO) {
        return cylinderInOutDetailMapper.selectPage(pageReqVO);
    }

}